package com.dong.repeatsubmit.controller;

import com.dong.repeatsubmit.annotation.NoRepeatSubmit;
import com.dong.repeatsubmit.cache.CacheUtil;
import com.dong.repeatsubmit.entity.AppNameConfigVO;
import com.dong.repeatsubmit.entity.User;
import com.dong.repeatsubmit.service.ChangeSkinService;
import com.dong.repeatsubmit.service.UserService;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.LoadingCache;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.StopWatch;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("/user/v1")
@Slf4j
public class UserController {
    @Autowired
    UserService userService;


    @RequestMapping("/create")
    @NoRepeatSubmit
    public User create() {
        User user = new User();
        user.setAge(32);
        user.setSex(1);
        user.setUserName("许亚东");

        User userCache = (User) CacheUtil.get("user");
        if (Objects.isNull(userCache)){
            CacheUtil.put("user",user);
        }

        return userCache;
    }


    @RequestMapping("/getTime")
    public List<AppNameConfigVO> getTime() {
        return userService.getTime();
    }

    @RequestMapping("/getConfig")
    public List<AppNameConfigVO> getConfig() {
        long start = System.currentTimeMillis();
        List<AppNameConfigVO> appNameConfigVOS = new ChangeSkinService().doChangSkin();
        log.info("getConfig 请求执行时长:{}",System.currentTimeMillis() - start);
        return appNameConfigVOS;
    }
}